package com.siwei.mes.entity.experiment;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 外委托(ExperimentOuter)实体类
 *
 * @author linzi
 * @since 2024-07-26 21:00:44
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_experiment_outer")
@ApiModel(value = "ExperimentOuter", description = "外委托")
public class ExperimentOuter implements Serializable {
    private static final long serialVersionUID = 903168424259608629L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "外委托主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "外委托主键id为空")
    private Long id;
    /**
     * 外委托编号
     */
    @Column(name = "outer_no")
    @ApiModelProperty(value = "外委托编号", name = "outerNo")
    private String outerNo;
    /**
     * 报告编号
     */
    @Column(name = "report_no")
    @ApiModelProperty(value = "报告编号", name = "reportNo")
    private String reportNo;
    /**
     * 物料类型  字典 MATERIAL_TYPE   1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
     */
    @Column(name = "materials_type")
    @ApiModelProperty(value = "物料类型  字典 MATERIAL_TYPE", name = "materialsType")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "物料类型为空")
    private Long materialsType;
    /**
     * 物料及规格配置id  pk_materials_spec_config的id
     */
    @Column(name = "spec_id")
    @ApiModelProperty(value = "物料及规格配置id  pk_materials_spec_config的id", name = "specId")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "材料为空")
    private Long specId;
    /**
     * 试验项目code  试验项目表
     */
    @Column(name = "test_project_code")
    @ApiModelProperty(value = "试验项目code  试验项目表 ", name = "testProjectCode")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "试验项目code为空")
    private String testProjectCode;
    /**
     * 试验项目名称
     */
    @Column(name = "test_project_name")
    @ApiModelProperty(value = "试验项目名称", name = "testProjectName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "试验项目名称为空")
    private String testProjectName;
    /**
     * 检测阈值
     */
    @Column(name = "check_threshold")
    @ApiModelProperty(value = "检测阈值", name = "checkThreshold")
    private String checkThreshold;
    /**
     * 检测结论
     */
    @Column(name = "check_result")
    @ApiModelProperty(value = "检测结论", name = "checkResult")
    private String checkResult;
    /**
     * 报告时间
     */
    @Column(name = "report_time")
    @ApiModelProperty(value = "报告时间", name = "reportTime")
    private Date reportTime;
    /**
     * 检测单位
     */
    @Column(name = "check_company")
    @ApiModelProperty(value = "检测单位", name = "checkCompany")
    private String checkCompany;
    /**
     * 批准时间
     */
    @Column(name = "approve_time")
    @ApiModelProperty(value = "批准时间", name = "approveTime")
    private Date approveTime;

    /**
     * 附件  多个用逗号隔开
     */
    @Column(name = "attachments")
    @ApiModelProperty(value = "附件  多个用逗号隔开", name = "attachments")
    private String attachments;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    /**
     * 材料名称
     */
    @Transient
    @ApiModelProperty(value = "材料名称", name = "materialsName")
    private String materialsName;

    @Transient
    @ApiModelProperty(value = "物料简称")
    private String materialAbbreviation;

    /**
     * 材料规格
     */
    @Transient
    @ApiModelProperty(value = "材料规格", name = "materialsSpec")
    private String materialsSpec;

    @Transient
    @ApiModelProperty(value = "报告开始时间")
    private String reportTimeStart;

    @Transient
    @ApiModelProperty(value = "报告结束时间")
    private String reportTimeEnd;

    public ExperimentOuter init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date()).setIsDel(0)
                    .setOuterNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT_OUTER.getCode()));
        }
        return this;
    }
}
